package minibank.core;

import java.math.BigDecimal;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 账户实体类
 *
 * @author 张俊辉
 */

public class Account {

    private final String id;

    private BigDecimal balance;

    private final ReentrantLock lock = new ReentrantLock();

    public Account(String id, BigDecimal balance) {
        this.id = id;
        this.balance = balance;
    }

    public String getId() {
        return id;
    }

    public BigDecimal getBalance() {
        return balance;
    }

    public void deposit(BigDecimal amount) {
        balance = balance.add(amount);
    }

    public void withdraw(BigDecimal amount) {
        balance = balance.subtract(amount);
    }

    public ReentrantLock getLock() {
        return lock;
    }
}
